//
//  HMEmoticonPopoView.swift
//  SinaWeibo
//
//  Created by apple on 16/10/9.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit
import pop

class HMEmoticonPopoView: UIView {

    @IBOutlet weak var emoticonButton: HMEmoticonButtton!
    
    
    var lastEmoticon: HMEmoticon?
    //增加类方法 加载该视图
    class func loadPopoView() -> HMEmoticonPopoView {
        let nib = UINib(nibName: "HMEmoticonPopoView", bundle: nil)
        return nib.instantiate(withOwner: nil, options: nil).last as! HMEmoticonPopoView
    }
    
    
    func show() {
        
        if let em = lastEmoticon {
            if em.chs == emoticonButton.emoticon?.chs {
                //是同一个图片表情就返回
                print("图片表情")
                print("~~~~~~~~~~~~~~~~~~~~~~")
                return
            }
            if em.code == emoticonButton.emoticon?.code {
                //是同一个emoji表情
                print("emoji表情")
                print("~~~~~~~~~~~~~~~~~~~~~~")
                return
            }
        }
    
        let anim = POPSpringAnimation(propertyNamed: kPOPLayerPositionY)!
        
        anim.fromValue = 40
        anim.toValue = 25
        
        anim.springBounciness = 20
        anim.springSpeed = 20
        emoticonButton.pop_add(anim, forKey: nil)
        //将上一次的表情模型记录下来
        lastEmoticon = emoticonButton.emoticon
    }

}
